package cn.maple.es.web.controller;

import cn.maple.es.domain.BookBean;
import cn.maple.es.service.BookService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Optional;

@Controller
@RequestMapping("es")
public class ElasticController {
    @Autowired
    private BookService bookService;

    @RequestMapping("/save")
    //添加修改
    @ResponseBody
    public void SaveOrUpt(BookBean book){
        System.out.println(book);
        bookService.save(book);
    }
    //删除
    @RequestMapping("/remove")
    public void delete(BookBean blog){
        bookService.delete(blog);
    }
    //查询全部
    @RequestMapping("/findAll")
    public List<BookBean> findAll(){
        return bookService.findAll();
    }

    //查询单个
    @RequestMapping("/findOne")
    public Optional<BookBean> findOne(String id){
        Optional<BookBean> one = bookService.findOne(id);
        return one;
    }
    //分页
    @RequestMapping("/pageList")
    public List<BookBean> pageList(){
        List<BookBean> bookBeans = bookService.pageList();
        return bookBeans;
    }

}

